<template>
	<view class="gulist-title">
		<view class="gulist-item-title">
			<text style="width: 30%;">币种</text>
		</view>
		
		<view class="gulist-item-body">
			<text style="width: 23%;">价格</text>
			<text style="width: 23%;">涨跌幅</text>
			<text style="width: 23%;">涨跌额</text>
		</view>
	</view>
	
	<view class="gulist-item" v-for="item,id in guList" :key="id" @click="jumpPage(item)">
		<view class="gulist-item-title">
			<text>{{item.biName}}</text>
			<text>{{item.biId}}</text>
		</view>
		<view class="gulist-item-body green" v-if="item.color == 1">
			<text>{{item.biPrice}}</text>
			<text>{{item.biFu}}</text>
			<text>{{item.biE}}</text>
		</view>
		<view class="gulist-item-body red" v-else-if="item.color == 2">
			<text>{{item.biPrice}}</text>
			<text>{{item.biFu}}</text>
			<text>{{item.biE}}</text>
		</view>
		<view class="gulist-item-body" v-else>
			<text>{{item.biPrice}}</text>
			<text>{{item.biFu}}</text>
			<text>{{item.biE}}</text>
		</view>
		
	</view>
	
</template>

<script>
	export default {
		data() {
			return {
				guList:null,
				userInfo:null,
				user_token:null
			};
		},
		onLoad() {
			this.getUserInfo()
			this.getGulist()
		},
		methods:{
			getUserInfo(){
				let that = this
				if(that.userInfo == null){
					uni.getStorage({
						key: 'user_token',
						success: function (res) {
							console.log(res)
							that.user_token = res.data
							that.checkUser()
						},
						fail: function(res){
							uni.showToast({
								title:'请先登录',
								icon:'none',
								success() {
									uni.redirectTo({
										url:'/pages/login/login',
									})
								}
							})
							
						}
					});
				}
			},
			checkUser(){
				let that = this
				uni.request({
					url:getApp().globalData.baseUrl + '/api/user/getUserInfo',
					method:'POST',
					header: {token:that.user_token},
					success(res) {
						if(res.data.code == 401){
							uni.removeStorageSync({
								key:'user_token',
								success() {
									uni.showToast({
										icon:'none',
										title:'登录已失效,请重新登录',
										success() {
											setTimeout(function(){
												uni.redirectTo({
													url:'/pages/login/login'
												})
											})
										}
									})
								}
							})
						}
						that.userInfo = res.data.data
					},
					fail() {
						uni.showToast({
							title:'网络错误',
							icon:'none',
						})
					}
				})
			},
			getGulist(){
				let that = this
				uni.request({
					url:getApp().globalData.baseUrl + "/api/index/getGulist",
					header:{token:that.user_token},
					method:'POST',
					success(res) {
						that.guList = res.data.data.GuList
					}
				})
			},
			jumpPage(item){
				window.location.href = item.navUrl
			}
		}
	}
</script>

<style lang="scss">
	page{
		background: #f4f4f4;
		margin: 0;
		padding: 0;
	}
	.green{
		color: #44c978 !important;
	}
	.red{
		color: #fe0000 !important;
	}
	.gulist-item-body{
		width: 70%;
		display: flex;
		justify-content: space-between;
		text-align: center;
		
		
	}
	.gulist-title{
		// width: 100%;
		background: #fff;
		display: flex;
		justify-content: center;
		border-bottom: 1px solid #f5f7fa;
		padding: .6rem;
	}
	.gulist-title>text{
		text-align: center;
	}
	.gulist-item{
		    background: #fff;
		// width: 100%;
		padding: .6rem;
		display: flex;
		justify-content: center;
		align-items: center;
		border-bottom: 1px solid #f5f7fa;
	}
	.gulist-item-body > text{
		width: 23%;
		text-align: center;
	}
	.gulist-item-title{
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		width: 30%;
		text-align: center;
	}
</style>
